<?php
class XPFace {
    static public $action;
    static public function getRegion($regionId) {
        //xpface config
        $xpFaceConfigLoader = XPFaceConfigLoader::getInstance();
        $xpFaceConfig = $xpFaceConfigLoader->getXPFaceConfig();
        //var_dump($xpFaceConfig);
        
        //page config
        $pageConfig = $xpFaceConfigLoader->getPageConfig();
        //var_dump($pageConfig);
        
        $_config = $pageConfig[self::$action->page_id];
        
        //uimodule
        $uimoduleSrc = $_config->regions[$regionId];
        //var_dump($uimoduleSrc);
        if (!$uimoduleSrc) {
            return;
        }
        //uimodule file
        $uimoduleFile = $xpFaceConfig["parsed_tpl_path"]->value."/".$uimoduleSrc.".php";
        if (!file_exists($uimoduleFile)) {
            return ;
        }
        
        $_data = self::$action->getData();
        foreach ($data = $_data["binds"] as $key => $source) {
            $$key = DataSourceFactory::getData($source);
        }
        if (!empty($_data[md5($uimoduleSrc)])) {
            foreach ($_data[md5($uimoduleSrc)] as $key => $source) {
                $$key = DataSourceFactory::getData($source);
            }
        }
        //var_dump($_page);
        $_pagePermissions = $_data["__permission__"];
        $_pageId = self::$action->page_id;
        include($uimoduleFile);
    }
    static public function setAction($action) {
        self::$action = $action;
    }
    
}
